//
//  ViewController.m
//  UIViewAnimation(2)
//
//  Created by dllo on 16/8/22.
//  Copyright © 2016年 ZHW. All rights reserved.
//

#import "ViewController.h"
#import "UIView+ChangeFrame.h"
@interface ViewController ()
@property (nonatomic, strong) UIView *animationView;
@property (nonatomic, strong) UIButton *animationButton;
@property (nonatomic, strong) UIButton *animationButtonTwo;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.animationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    _animationView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:_animationView];
    
    // 参数3: 0.0 - 1.0 数值越小, 阻力越小; 数值越大, 阻力越大
    // 参数4: 速度
    // 参数5: 选项
    [UIView animateWithDuration:2 delay:0 usingSpringWithDamping:1.0f initialSpringVelocity:0.0f options:UIViewAnimationOptionRepeat animations:^{
//       _animationView.z_width = 200;
       _animationView.z_height = 100;
   } completion:^(BOOL finished) {
       
   }];
    
    self.animationButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _animationButton.frame = CGRectMake(100, 100, 200, 200);
    _animationButton.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:_animationButton];
    [_animationButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    self.animationButtonTwo = [UIButton buttonWithType:UIButtonTypeCustom];
    _animationButton.frame = CGRectMake(200, 100, 100, 100);
    _animationButton.backgroundColor = [UIColor redColor];
    
}

- (void)buttonClicked:(UIButton *)button {
    // 参数1: 需要执行动画的view
    // 参数2: 持续时间
    // 参数3: 动画效果
//    [UIView transitionWithView:_animationView duration:5 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
//        _animationView.z_height = 200;
//    } completion:^(BOOL finished) {
//        // 动画可以嵌套动画
//        [UIView animateWithDuration:0.5 animations:^{
//            _animationView.z_height = 100;
//        }];
//    }];
    
    // toView会被添加到fromView的父视图上, 然后fromView从父视图上被移除
    [UIView transitionFromView:_animationButton toView:_animationButtonTwo duration:5 options:UIViewAnimationOptionTransitionCurlDown completion:^(BOOL finished) {
        
    }];
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
